home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / SNIP9_91.ARJ / ATR2ANSI.C1 < prev    next >
Text File  |  1991-09-06  |  3KB  |  69 lines

  1. /************************************************************************/
  2. /*      Video attribute to ANSI command processor                       */
  3. /*                                                                      */
  4. /*      This is a short program demonstrating a technique for reading   */
  5. /*      the current screen video attribute and using it to build        */
  6. /*      command strings for ANSI.SYS-compatible color.                  */
  7. /*                                                                      */
  8. /*      Public domain demo by Bob Stout                                 */
  9. /*                                                                      */
  10. /************************************************************************/
  11.  
  12. #include <stdio.h>
  13. #include <dos.h>
  14. #include <mflconio.h>           /* Part of MFLZT shareware library      */
  15. #define PAGE(title)
  16. PAGE(main)                      /* Used by MicroFirm PR for listing     */
  17.  
  18. /* First define the black and white defaults                            */
  19.  
  20. int     vid_nrm = 0x7,          /* Normal video mode (wht on blk)       */
  21.         vid_rev = 0x70,         /* Reverse video mode (blk on wht)      */
  22.         vid_grf = 0x7,          /* Line graphics (same as normal)       */
  23.         vid_grv = 0x70;         /* Reverse graphics (same as reverse)   */
  24. int     vid_mode;
  25. char *my_color, *your_color;
  26.  
  27. main()
  28. {
  29.         int oldvatr;
  30.         char *p;
  31.         union REGS regs;
  32.         char *make_ansi(int);
  33.  
  34.         regs.h.ah = 0xf;                /* Get display page in bh       */
  35.         int86(0x10,®s,®s);
  36.         vid_mode = regs.h.al;           /* Save video mode              */
  37.         regs.h.ah = 0x8;                /* get color/attribute          */
  38.         int86(0x10,®s,®s);
  39.         oldvatr = regs.h.ah;
  40.  
  41.         your_color = make_ansi(oldvatr);
  42.  
  43.         if (vid_mode != MONO)
  44.         {
  45.                 if (vid_mode != CLR80)
  46.                         vmode(CLR80);
  47.  
  48.                 printf("\nWe need to print something in the standard"
  49.                        " screen color\n\n");
  50.  
  51.                 /* Change the foreground                        */
  52.  
  53.                 my_color = make_ansi(oldvatr ^ 0x4);
  54.                 printf("%sFirst we'll change the foreground...%s\n",
  55.                         my_color, your_color);
  56.  
  57.                 /* Change the background                        */
  58.  
  59.                 my_color = make_ansi(oldvatr ^ 0x44);
  60.                 printf("%s...then we'll change the background%s\n\n",
  61.                         my_color, your_color);
  62.  
  63.                 /* Return to the way it was                     */
  64.  
  65.                 printf("Now we'll show things are back the way they were\n");
  66.         }
  67.         else    printf("\aSorry, B&W doesn't cut it\n");
  68. }
  69.